[#14] Add type family to display list of types separated by commas#22
[#14] Add type family to display list of types separated by commas#22dalpd wants to merge 1 commit intokowainik:mainfrom
Conversation
chshersh
left a comment
There was a problem hiding this comment.
Hi @dalpd,
Thanks for your contribution! I described an alternative design for this problem, which I believe will result in a smaller and cleaner code. But I hope that you were able to practice type-level programming in Haskell and learned something new nevertheless from working on this issue 🤗
| -- | Internal type family to go from a `Type` to a `Symbol` representation. | ||
| -- The names for types without `Generic` instances have to be defined | ||
| -- manually, and we do so for a handful of common types. | ||
| type family TypeName (a :: Type) :: Symbol where | ||
| TypeName Char = "Char" | ||
| TypeName String = "String" | ||
| TypeName Int = "Int" | ||
| TypeName (Maybe a) = AppendSymbol "Maybe " (TypeName a) | ||
| TypeName [a] = AppendSymbol "[" (AppendSymbol (TypeName a) "]") | ||
| TypeName (D1 ('MetaData name _ _ _) _ _) = name | ||
| TypeName a = TypeName (Rep a ()) |
There was a problem hiding this comment.
I think this approach is not extensible. Users of type-errors-pretty cannot create new instances of TypeName. And the library cannot provide instances for all types 😞
To solve this problem nicely, the CommaSeparated type family can return a type of kind ErrorMessage instead of Symbol. The type-level operator <> already converts types and type-level symbols to a nice stringified representation that can be later reused in error messages.
Hi there!
I initially took a stab at this during summer break but I never got a chance to get back to it, that is until today.
I previously was thinking about asking what to do with
Maybe aand[a]as they were represented asMaybeand[]when left to the Generic instance but I think that's no good so also added them inTypeName.